package com.example.piedrapapeltijeralagartospok;

import controlador.Controlador;
import controlador.Listener_Ganar;
import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class GanaActivity extends Activity {
	private Controlador c=new Controlador(this);
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_gana);
		Listener_Ganar lg = new Listener_Ganar(this);
 
		TextView ganador = (TextView)findViewById(R.id.ganador);

		

		ganador.setText(this.getIntent().getExtras().getString("ganador"));

		int seleccion1 = this.getIntent().getExtras().getInt("seleccion_j1");
		int seleccion2 = this.getIntent().getExtras().getInt("seleccion_j2");

		ImageView imagenJ1 = (ImageView) findViewById(R.id.resultadoJugador1);
		this.setImagenSeleccionada(seleccion1, imagenJ1);

		ImageView imagenJ2 = (ImageView) findViewById(R.id.resultadoJugador2);
		this.setImagenSeleccionada(seleccion2, imagenJ2);
		
		Button volver_jugar = (Button) findViewById(R.id.volverAJugar);
		volver_jugar.setOnClickListener(lg);
		
		Button volver_menu = (Button) findViewById(R.id.menuPrincipal);
		volver_menu.setOnClickListener(lg);
		

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public void setImagenSeleccionada(int seleccion, ImageView iv) {

		switch (seleccion) {
		case 1:
			iv.setImageResource(R.drawable.piedra);
			break;

		case 2:
			iv.setImageResource(R.drawable.papel);
			break;

		case 3:
			iv.setImageResource(R.drawable.tijera);
			break;

		case 4:
			iv.setImageResource(R.drawable.lagarto);
			break;

		case 5:
			iv.setImageResource(R.drawable.spok);
			break;

		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_BACK) {

			Toast.makeText(this, "No hagas trampas", Toast.LENGTH_LONG).show();
		} else {
			// para las demas cosas, se reenvia el evento al listener habitual
			return super.onKeyDown(keyCode, event);
		}
		return false;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		if (!c.onOptionsItemSelected(item)) {

			super.onOptionsItemSelected(item);

		}
		return true;
	}
}
